#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

/**
 * 递归法
 */
class Test01{
public:
	int getHeight(TreeNode* node){
		if(node == NULL){
			return 0;
		}
		int leftHeight = getHeight(node->left);
		if(leftHeight == -1){
			return -1;
		}
		int rightHeight = getHeight(node->right);
		if(rightHeight == -1){
			return -1;
		}
		int diff = abs(leftHeight - rightHeight);
		if(diff > 1){
			return -1;
		}else{
			return 1 + max(leftHeight, rightHeight);
		}
	}
	
	bool isBalanced(TreeNode* root){
		if(root == NULL){
			return true;
		}
		
	}
	
};

class Test{
public:
	int getHeight(TreeNode* node){
		if(node == NULL){
			return 0;
		}
		int leftHeight = getHeight(node->left);
		if(leftHeight == -1){
			return -1;
		}
		int rightHeight = getHeight(node->right);
		if(rightHeight == -1){
			return -1;
		}
		int h = abs(leftHeight - rightHeight);
		if(h > 1){
			return -1;
		}else{
			return 1 + max(leftHeight,rightHeight);
		}
	}
	bool isBalanced(TreeNode* root) {
		int res = getHeight(root);
		if(res == -1){
			return false;
		}
		return true;
	}
};



int main(){
	
	return 0;
}
